<include file="Common/header" />
<title>添加房间</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="panel panel-primary">
			<div class="panel-header">房间基本信息</div> 
			<div class="panel-body">
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">* </span>房间编号：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['room_number']}" id="room_number" name="room_number">
					</div>

					<label class="form-label col-2"><span class="c-red">* </span>房间楼层：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['floor']}" id="floor" name="floor">
					</div>
				
					<label class="form-label col-2"><span class="c-red">* </span>房间户型：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['root_type']}" id="root_type" name="root_type" />
					</div>
				</div>
				<div class="row cl">	
					<label class="form-label col-2"><span class="c-red">* </span>出租类型：</label>
					<div class="formControls col-2">
						<span class="select-box">
							<select class="select radius" name="rent_type" id="rent_type">
								<option value="长租" {$info['rent_type'] == '长租' ? 'selected' : ''}>长租</option>
								<option value="日租" {$info['rent_type'] == '日租' ? 'selected' : ''}>日租</option>
							</select>
						</span>
					</div>
				
					<label class="form-label col-2"><span class="c-red">* </span>租用押金：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['deposit']}" id="deposit" name="deposit">
					</div>

					<label class="form-label col-2"><span class="c-red">* </span>房间租金：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['rent']}" id="rent" name="rent" />
					</div>
				</div>

				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">* </span>物业费用：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['property']}" id="property" name="property" />
					</div>

					<label class="form-label col-2"><span class="c-red">* </span>房间状态：</label>
					<div class="formControls col-2">
						<span class="select-box">
							<select class="select radius" name="visible" id="visible">
								<option value="1" {$info['visible'] == 1 ? 'selected' : ''}>可用</option>
								<option value="0" {$info['visible'] == 0 ? 'selected' : ''}>不可用</option>
							</select>
						</span>
					</div>
				
					<label class="form-label col-2">备注：</label>
					<div class="formControls col-2">
						<input type="text" class="input-text radius" value="{$info['remark']}" id="remark" name="remark" />
					</div>
				</div>
			</div>
		</div>
		<div class="panel panel-warning">
			<div class="panel-header">租金规则</div>
			<div class="panel-body">
				<div class="row cl">
					<table class="table table-border table-bordered table-bg">
						<thead>
							<tr class="text-c">
								<th>开始时间</th>
								<th>结束时间</th>
								<th>月租</th>
								<th>物业费</th>
								<th>押金</th>
								<th width="70">操作</th>
							</tr>
						</thead>
						<tbody class="ntbody">
							<?php if($attrcount){ ?>
							<?php foreach($rentdata as $k=>$rent){ ?>
							<tr>
								<td>
									<span class="select-box radius">
										<input class="select form-control layer-date radius times" name="param[{$k}][btime]" value="{$rent['begintime']|date='Y-m-d', ###}" onclick="times();" />
									</span>
								</td>
								<td>
									<span class="select-box radius">
										<input class="select form-control layer-date radius times" name="param[{$k}][etime]" value="{$rent['endtime']|date='Y-m-d', ###}" onclick="times();" />
									</span>
								</td>
								<td>
									<input class="input-text radius" name="param[{$k}][rent]" value="{$rent['rent']}" />
								</td>
								<td>
									<input class="input-text radius" name="param[{$k}][property]" value="{$rent['property']}" />
								</td>
								<td>
									<input class="input-text radius" name="param[{$k}][deposit]" value="{$rent['deposit']}" />
								</td>
								<?php if($k > 0){ ?>
								<td>
									<a title="移除" href="javascript:void(0);" class="btn btn-danger radius deleteBtns" style="height: 30px;" onclick="delLine(this);"><i class="Hui-iconfont">&#xe6a1;</i></a>
								</td>
								<?php }else{ ?>
								<td></td>
								<?php } ?>
							</tr>
							<?php } ?>
							<?php }else{ ?>
							<tr>
								<td>
									<span class="select-box radius">
										<input class="select form-control layer-date radius times" name="param[0][btime]" value="" onclick="times();" />
									</span>
								</td>
								<td>
									<span class="select-box radius">
										<input class="select form-control layer-date radius times" name="param[0][etime]" value="" onclick="times();" />
									</span>
								</td>
								<td>
									<input class="input-text radius" name="param[0][rent]" value="" />
								</td>
								<td>
									<input class="input-text radius" name="param[0][property]" value="" />
								</td>
								<td>
									<input class="input-text radius" name="param[0][deposit]" value="" />
								</td>
								<td></td>
							</tr>
							<?php } ?>
						</tbody>	
					</table>
					
					<table class="table table-border table-bordered pt-5">
						<tr class="text-c">
							<td>
								<button type="button" class="btn btn-primary radius"><i class="icon-ok"></i> 添加一行</button>
								<button type="button" class="btn btn-success radius roleSubmit"><i class="icon-ok"></i> 确定</button>
							</td>
						</tr>
					</table>
				</div>
			</div>
		</div>
		<input type="hidden" id="room_id" name="room_id" value="{$info['room_id']}" />
	</form>
</div>

<script>
	function delLine(obj){
		$(obj).closest('tr').remove();
	}

	function times(){
		laydate({istime: true, format: 'YYYY-MM-DD'});
	}

	$(document).ready(function(){
		var line = '{$attrcount}' || 1;
		//添加一行
		$(".btn-primary").on('click', function(){
			var html = $(".ntbody tr:eq(0)").html();
			line = line <= 0 ? 1 : line;
			
			var remove = '<a title="移除" href="javascript:void(0);" class="btn btn-danger radius deleteBtns" style="height: 30px;" onclick="delLine(this);"><i class="Hui-iconfont">&#xe6a1;</i></a>';
			//替换全部参数
			html = html.replace(/param\[(0)\]/g, 'param['+ line/1 +']');
			console.log(html);
			//替换
			html = html.replace('<td></td>', '<td>'+ remove +'</td>');
			//追加规则栏
			$(".ntbody").append('<tr class="text-c">' + html + '</tr>');
			//规则计数
			line = line/1 + 1;
		});

		$(".roleSubmit").on('click', function(){
			/**
			 * 验证参数
			 **/
			var roomnumber = $("#room_number").val();
			if(!roomnumber.length){
				layer.msg('请输入房间编号', {icon: 5, time: 2000});
				return false;
			}

			if(isNaN($("#floor").val())){
				layer.msg('请输入房间楼层', {icon: 5, time: 2000});
				return false;
			}

			if(isNaN($("#deposit").val())){
				layer.msg('请输入租房押金', {icon: 5, time: 2000});
				return false;
			}

			if(isNaN($("#rent").val())){
				layer.msg('请输入房间月租', {icon: 5, time: 2000});
				return false;
			}

			if(isNaN($("#property").val())){
				layer.msg('请输入房间物业费', {icon: 5, time: 2000});
				return false;
			}

			$.post('index.html', $("#form-user-character-add").serialize(), function(data){
				if(data == '操作成功'){
					layer.msg('操作成功', {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	                    parent.layer.close(index);
					});
				}else{
					layer.msg(data, {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>